package com.hongkzh.www.look.media.view.framgent;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hongkzh.www.R;
import com.hongkzh.www.look.media.presenter.MedPopPresenter;
import com.hongkzh.www.look.media.view.adapter.MedPopRvAdapter;
import com.hongkzh.www.look.media.view.iview.MedPopIView;
import com.hongkzh.www.look.model.bean.CategoryBean;
import com.hongkzh.www.look.model.bean.CityAdvBean;
import com.hongkzh.www.look.model.bean.CityBean;
import com.hongkzh.www.look.model.bean.DayIntegralBean;
import com.hongkzh.www.look.model.bean.HotAdvBean;
import com.hongkzh.www.look.model.bean.StaticBean;
import com.hongkzh.www.look.view.activity.AttentionActivity;
import com.hongkzh.www.look.view.activity.DayIntegralActivity;
import com.hongkzh.www.look.view.activity.EarnActivity;
import com.hongkzh.www.look.view.activity.PublishActivity;
import com.hongkzh.www.look.view.activity.RecordActivity;
import com.hongkzh.www.look.view.activity.SearchActivity;
import com.hongkzh.www.look.view.activity.TaskActivity;
import com.hongkzh.www.look.view.adapter.LkRvAdapter;
import com.hongkzh.www.look.view.iview.LKIView;
import com.hongkzh.www.view.customview.MyFooter;
import com.hongkzh.www.view.fragment.BaseFragment;
import com.liaoinstan.springview.widget.SpringView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 自媒体 人气
 */
public class MedPopFragment extends BaseFragment<MedPopPresenter> implements MedPopIView, SpringView.OnFreshListener, MedPopRvAdapter.OnItemClickListener {
    Unbinder unbinder;
    @BindView(R.id.medpop_rv)
    RecyclerView medpopRv;
    @BindView(R.id.medpop_sv)
    SpringView medpopSv;
    private MyFooter myFooter;
    private boolean lastPage;
    private MedPopRvAdapter medPopRvAdapter = new MedPopRvAdapter();

    @Override
    protected int getLayoutId() {
        return R.layout.fagment_medpop;
    }

    @Override
    protected void init() {
        setPresenter(new MedPopPresenter());
        getPresenter().getHotAdvList();

        myFooter = new MyFooter(getActivity());
        medpopSv.setFooter(myFooter);

        medpopRv.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        medpopRv.setAdapter(medPopRvAdapter);
    }

    @Override
    protected void setListener() {
        medpopSv.setListener(this);
        medPopRvAdapter.setOnItemClickListener(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onLastPage(boolean lastPage) {
        this.lastPage = lastPage;
        myFooter.setLastPage(lastPage);
    }

    @Override
    public void setHotAdvList(com.hongkzh.www.look.media.model.bean.HotAdvBean hotAdvBean) {
        medPopRvAdapter.addHotAdvList(hotAdvBean);
        medPopRvAdapter.notifyDataSetChanged();
        medpopSv.onFinishFreshAndLoad();
    }

    @Override
    public void onError(Exception e) {
        Log.e("https", String.valueOf(e));
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadmore() {
        if (lastPage) medpopSv.onFinishFreshAndLoad();
        else getPresenter().loadmore();
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onItemClick(String uid, String id) {
//        Intent intent = new Intent(getActivity(), WatchActivity.class);
//        intent.putExtra("uid", uid);
//        intent.putExtra("id", id);
//        startActivity(intent);
    }
}
